$(window).load(function() {
    $("#main_navigation ul li").hide();
    $("#contact_link").delay(750).animate({
        bottom: 250
    },{
        duration: 'slow',
        easing: 'easeInBounce'
    }).animate({
        bottom: 100
    },{
        duration: 'slow',
        easing: 'easeOutBounce'
    });
    setContentHeight();
    setTimeout("sequentialFadeIn('#main_navigation ul li')",500);
    if ($.cookie("lead_id") != null) {
        var lead_id = $.cookie("lead_id");
        getLeadDetails(lead_id);
    }
    $("li").hover(
    function() {
        $(this).find('a').addClass('text_shadow');
    },
    function() {
        $(this).find('a').removeClass('text_shadow');
    });
    fadeContent("home-principal");
    $("#secondary_navigation li").click(function() {
        $("#secondary_navigation li").removeClass('secondary_selected');
        var div_name = $(this).attr('class');
        $(this).addClass('secondary_selected');
        fadeContent(div_name);
    })
    var section_name = $("#secondary_navigation").attr('class');
    highlightPrimaryNavigation(section_name)
    $("select").selectBox();
    $("#contact_close").click(function() {
        $("#contact_form_contents").fadeOut("slow");
        $("#contact_form").animate({
            right: '-350',
            height: '25'
        }, 1000, function() {
            $("#contact_form").hide();
        });
    });
    $("#contact_link").click(function() {
        $("#contact_form").show();
        $("#contact_form").animate({
            right: '115',
            height: '615'
        }, 1000, function() {
            $("#contact_form_contents").fadeIn("slow");
        });
    });
    $("#share_link").click(function() {
        $(this).addClass("side_button_hover");
        $("#sharing_form").fadeIn("slow");
    });
    $("#sharing_close").click(function() {
        $("#share_link").removeClass("side_button_hover");
        $("#sharing_form").fadeOut("slow");
    })
    $("#form_contact").validate({
        errorClass: "invalid_form_field",
        rules: {
            full_name: "required",
            email1: {
                required: true,
                email: true
            },
            project_details: "required"
        },
        submitHandler: function() {
            var full_name = $("#full_name").val();
            var phone_work = $("#phone_work").val();
            var email1 = $("#email1").val();
            var time_zone = $("#time_zone").val();
            var contact_method = $("#contact_method").val();
            var project_details = $("#project_details").val();
            $.ajax({
                type: "POST",
                url: "controller/murillodigital.controller.php",
                data: {
                    controller_action: "submit_contact_form",
                    full_name: full_name,
                    phone_work: phone_work,
                    email1: email1,
                    time_zone: time_zone,
                    contact_method: contact_method,
                    project_details: project_details
                },
                dataType: 'json',
                success: function(data) {
                    if (data.error.number == "0") {
                        $.cookie('lead_id',data.id, {
                            expires: 365,
                            path: '/'
                        });
                        $("#contact_form").fadeOut("fast");
                        $("#welcome_legend h1").html(full_name + ", pronto le estaremos contactando.<br/>Est&aacute; un paso m&aacute;s cerca de crear una experiencia<br/>&uacute;nica para sus usuarios!");
                    }
                }
            })
        }
    });
    $(".icon_img").hover(function() {
        var id_name = $(this).attr("id");
        var tech_name = id_name.split("_");
        var tech_section_id = "details_" + tech_name[1];
        $("#" + tech_section_id).fadeIn("fast");
    }, function() {
        var id_name = $(this).attr("id");
        var tech_name = id_name.split("_");
        var tech_section_id = "details_" + tech_name[1];
        $("#" + tech_section_id).fadeOut("fast");
    });
})
$(window).resize(function() {
    setContentHeight();
})
function setContentHeight() {
    md_window_width = $(window).width();
    md_window_height = $(window).height();
    md_content_area_height = md_window_height - 238;
    $(".content_height").height(md_content_area_height);
    $("#parallax").css({
        width: md_window_width,
        height: md_window_height
    })
    $jq('#parallax').jparallax({},{});
}
function fadeContent(div_name) {
    $(".content_area").hide();
    $("#" + div_name).fadeIn("slow");
}
function highlightPrimaryNavigation(section_name) {
    $("#main_navigation").removeClass('primary_selected').removeClass('text_shadow');
    $("#" + section_name).addClass('primary_selected').addClass('text_shadow');
}
function getLeadDetails(lead_id) {
    $.ajax({
        type: "POST",
        url: "controller/murillodigital.controller.php",
        data: {
            controller_action: "get_lead_details",
            lead_id: lead_id
        },
        dataType: 'json',
        success: function(data) {
            var intro = "Hola " + data.first_name + "! El d&iacute;a " + data.date_contact + " recibimos su informaci&oacute;n.";
            if (data.current_status == "New") {
                var contact = "<br/>En las pr&oacute;ximas horas estaremos dando respuesta a su solicitud.";
            } else {
                var contact = "<br/>Nos alegra estar en contacto y compartir nuestra experiencia y creatividad con usted.";
            }
            var outro = "<br/>Esperamos pronto estar creando una experiencia &uacute;nica para sus usuarios!";
            $("#welcome_legend h1").hide().html(intro + contact + outro).delay(500).fadeIn("slow");
        }
    })
}
function sequentialFadeIn(selector) {
    var timed_delay = 500;
    $(selector).delay(timed_delay).each(function(n) {
        $(this).delay(n * timed_delay).fadeIn("slow");
    })
}